#ifndef __IAP_H__
#define __IAP_H__
#include "stm32l431xx.h"

// #define FLASH_BASE          0x08000000	//FLASH基地址
#define PAGE_SIZE	        2048	    //页大小
#define PAGE_NUM	        128		    //页数

/* 分区         大小        扇区        说明
bootloader      20K        0-10      引导程序
app             234K       11-126    应用程序
flag            2K         127       版本信息
*/
#define BOOTLOADER_ADDR         0x08000000
#define BOOTLOADER_PAGE_START   0
#define BOOTLOADER_PAGE_NUM     10
#define BOOTLOADER_FLASH_SIZE   (PAGE_SIZE * BOOTLOADER_PAGE_NUM)
#define APPLICATION_ADDR        (BOOTLOADER_ADDR + PAGE_SIZE * BOOTLOADER_PAGE_NUM)
#define APPLICATION_PAGE_START  10
#define APPLICATION_PAGE_NUM    (PAGE_NUM - BOOTLOADER_PAGE_NUM - 1)
#define APPLICATION_FLASH_SIZE  (PAGE_SIZE * APPLICATION_PAGE_NUM)
#define FLAG_ADDR               (APPLICATION_ADDR + PAGE_SIZE * APPLICATION_PAGE_NUM)
#define FLAG_PAGE_START         127
#define FLAG_PAGE_NUM           1
#define FLAG_FLASH_SIZE         (PAGE_SIZE * FLAG_PAGE_NUM)
// #define FLASH_

void bootloader_display(void);
void turn_to_app(void);
int8_t uart_getchar(uint8_t *data, uint32_t timeout);
int8_t uart_getstream(uint8_t *data, uint32_t len, uint32_t timeout);
void uart_putchar(uint8_t data);
int8_t get_iap_signal(uint32_t timeout);
uint32_t FLASH_PageMask(__IO uint32_t Size);
uint8_t FLASH_Erase_pages(uint32_t page, uint32_t NbPage);
uint8_t FLASH_Program_8bytes(uint32_t address, uint64_t doubleWord);
// void flash_test(void);
#endif /* __IAP_H__ */
